<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('售前未跟踪提醒') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('关注等级')" prop="levelConcern">

        <dictSelect
          v-model="queryParams.levelConcern"
          :clearable="true"
          dictionary="level_concern"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="dealTrackTimeList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目名称')" align="center" prop="dealName">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/deal/home/dealBaseHome',query:{id:scope.row.dealId,companyId:scope.row.companyId}}"
            :style="scope.row.lastMonth ? '' : 'color:red'"
            class="link_a"
          >{{ scope.row.dealName }}
          </router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('上次追踪时间')" align="center" prop="beforeTrackTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beforeTrackTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('上次追踪内容')" align="center" prop="beforeDetails" />
      <el-table-column :label="$t('关注等级')" align="center" prop="levelConcern">
        <template slot-scope="scope">
          <span>{{ getLevelConcern(scope.row.levelConcern) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listDealTrackTime } from '@/api/deal/track/dealTrackTime'

export default {
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 项目跟踪定时表格数据
      dealTrackTimeList: [],
      // 弹出层标题
      title: '项目跟踪定时',
      // 是否显示弹出层
      formOpen: false,
      // 查询参数
      queryParams: {
        dealId: undefined,
        personCharge: undefined,
        beforeTrackTime: undefined,
        beforeDetails: undefined,
        userId: undefined,
        timeId: undefined,
        levelConcern: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      timeId: undefined,
      levelConcerns: undefined
    }
  },
  created() {
    this.$bus.$emit('async_done')
    this.getDict()
  },
  methods: {
    // 初始化数据
    init(id) {
      if (id != null && id.id !== undefined) {
        this.queryParams.timeId = id.id
        this.timeId = id.id
        this.getList()
      }
    },
    /** 查询项目跟踪定时列表 */
    getList() {
      this.loading = true
      listDealTrackTime(this.queryParams).then(response => {
        this.dealTrackTimeList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        dealId: undefined,
        personCharge: undefined,
        beforeTrackTime: undefined,
        beforeDetails: undefined,
        userId: undefined,
        timeId: undefined,
        levelConcern: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.queryParams.timeId = this.timeId
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    getDict() {
      // 关注类型
      this.getDicts('level_concern').then(response => {
        this.levelConcerns = response.data
      })
    },
    getLevelConcern(key) {
      if (key === null || key === undefined || key === '') {
        return null
      }
      for (let i = 0; i < this.levelConcerns.length; i++) {
        const level = this.levelConcerns[i]
        if (level.dictValue === key) {
          return level.dictLabel
        }
      }
    }

  }
}
</script>
